/**
 * VisualTree.java created by zhangzhidong 
 * at 下午10:50:46 2016年4月20日
 */
package algorithm.CIG.binarytree;

import algorithm.CIG.base.TreeBase;
import algorithm.CIG.base.TreeNode;

/**
 * @author zhangzhidong
 *
 */
public class VisualTree extends TreeBase {
	
	
	
	
	
	public static void main(String args[]){
		TreeNode root =  generateTree();
		root.val = 5;
		printTree(root);
		sepratorLine();
		morrisIn(root);
		return ;
	}
	public static void printTree(TreeNode t){
		inOrderPrintTree(t,0 ,"H", 17);
		
	}
	private static void inOrderPrintTree(TreeNode head,int height,String to,int len){
		if(head==null){
			return;
		}
		inOrderPrintTree(head.right, height+1, "v", len);
		String val = to+head.val+to;
		int lenM = val.length();
		int lenL = (len-lenM)/2;
		int lenR = len - lenM - lenL;
		val = getSpace(lenL)+val+getSpace(lenR);
		System.out.println(getSpace(height*len)+val);
		inOrderPrintTree(head.left, height+1,"^", len);
		
	}
	public static String getSpace(int num){
		String space = " ";
		StringBuffer  buffer = new StringBuffer("");
		for(int i=0;i<num;i++){
			buffer.append(space);
		}
		return buffer.toString();
	}
}
